/** 
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 * 
 *SdPMOStandardizationRecordController
 * SD标准化人选档案
 * 
 * 修改纪录
 * 2021-12-09 版本：1.0 jiangtao 创建。
 * @version 版本：1.0
 * @author 作者：jiangtao
 * 创建日期：2021-12-09
 */

package com.topscomm.gpm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.topscomm.gpm.controller.auto.GpmPMOStandardizationRecordControllerAuto;
import org.springframework.web.bind.annotation.*;

import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: jiangtao
 * @date: 2021-12-09
 * @description:SD标准化人选档案Controller
 * @modify:
 */
@RestController
@RequestMapping("sd/pMOStandardizationRecord")
public class GpmPMOStandardizationRecordController extends GpmPMOStandardizationRecordControllerAuto implements IGpmPMOStandardizationRecordController {
	/**
	 * @author: jiangtao
	 * @date: 2021-12-09
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_user")) {
			String value = paraMap.get("qry_user").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and (usercode like '%{0}%' or username like '%{0}%') ", value);
		}
		if(paraMap.containsKey("query_chargeprovinces")) {
			StringBufferProxy sql1 = new StringBufferProxy();
			String value = paraMap.get("query_chargeprovinces").toString();
			if(!StringUtil.isEmpty(value)) {
				String[] array = value.split(",");
				for (String a:array) {
					sql1.appendSingle("or ',' || chargeprovinces || ','  like '%{0}%'",","+a+",");
				}
				if(sql.length()>0) {
					sql.appendSingle(" and ({0})",sql1.substring(2,sql1.length()));
				}
			}
		}
		return sql.toString();
	}

	/**
	 * @author: jiangtao
	 * @date: 2021-12-09
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	@Override
	@GetMapping(value = "/dataCodeList")
	public ResponseResult<Object> dataCodeList(@RequestParam(required = false) Map<String, Object> paraMap) {
		ResponseResult<Object> result = super.dataCodeList(paraMap);
		Map<String, Object> codeMap = (HashMap<String, Object>) result.getResult();
		List<Map<String, Object>> sdprojectleveltypeList = datacodeCache.getCodeListMap("GpmProjectLevelType", "", "sortcode");
		codeMap.put("sdprojectleveltypeList", sdprojectleveltypeList);
		List<Map<String, Object>> projectlevelList = datacodeCache.getCodeListMap("GpmProjectLevel", "", "sortcode");
		codeMap.put("projectlevelList", projectlevelList);
		return ResponseResult.ok(codeMap);
	}

	/**
	 * @description:查询当前用户是否为PMO(项目复盘用）
	 * @author: zhangjunyao
	 * @date: 2021-12-23
	 * @modify:
	 */
	@GetMapping(value = "/queryPMOPermission")
	public ResponseResult<Object> queryPMOPermission(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			boolean ispmo = this.service.queryPMOPermission(paraMap);
			return ResponseResult.ok(ispmo);
		} catch (Exception ex) {
			return this.handleControllerException(ex);
		}
	}
}

